﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Sockets;

namespace Server
{
    internal class Program
    {
        static void Main(string[] args)
        {
            TcpService service = new TcpService();
            service.Connected = (client, e) => { return EasyTask.CompletedTask; };//有客户端连接
            service.Closed = (client, e) => { return EasyTask.CompletedTask; };//有客户端断开连接
            service.Received = (client, e) =>
            {
                //从客户端收到信息
                string mes = e.ByteBlock.Span.ToString(Encoding.UTF8);
                Console.WriteLine($"已从{client.Id}接收到信息：{mes}");
                return EasyTask.CompletedTask;
            };
            service.StartAsync(7789).GetAwaiter().GetResult();//启动
            Console.ReadKey();
        }
    }
}
